package stdio.costa.imoca.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@NamedQueries({ @NamedQuery(name = "listByUuids", query = "from Image where uuid in (:uuids)"),
	@NamedQuery(name = "listLocalStored", query="from Image where url is null and processing = false")})
public class Image extends UuidEntity implements Serializable {

	private static final long serialVersionUID = -2037849792277521629L;

	private long size;
	
	private MocaUser owner;
	
	private String mediaType;
	
	@Lob
	@XmlTransient
	private byte[] data;
	
	private String thumbnailUrl;
	
	private String mediumUrl;
	
	private String largeUrl;
	
	private boolean processing;
	
	public Image() {
	}
	
	public Image(byte[] data, String mediaType, MocaUser owner) {
		this.data = data;
		this.mediaType = mediaType;
		this.size = data.length;
		this.owner = owner;
	}
	
	public void clearLocalStorage() {
		setData(null);
	}
	
	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public MocaUser getOwner() {
		return owner;
	}

	public void setOwner(MocaUser owner) {
		this.owner = owner;
	}

	public byte[] getData() {
		return data;
	}

	public void setData(byte[] data) {
		this.data = data;
	}

	public String getThumbnailUrl() {
		return thumbnailUrl;
	}

	public void setThumbnailUrl(String thumbnailUrl) {
		this.thumbnailUrl = thumbnailUrl;
	}

	public String getMediumUrl() {
		return mediumUrl;
	}

	public void setMediumUrl(String mediumUrl) {
		this.mediumUrl = mediumUrl;
	}

	public String getMediaType() {
		return mediaType;
	}

	public void setMediaType(String mediaType) {
		this.mediaType = mediaType;
	}

	public boolean isProcessing() {
		return processing;
	}

	public void setProcessing(boolean processing) {
		this.processing = processing;
	}

	public String getLargeUrl() {
		return largeUrl;
	}

	public void setLargeUrl(String largeUrl) {
		this.largeUrl = largeUrl;
	}
}
